/*
 * Copyright (C) 2010-2010 MaoJian Wu
 *
 * Author:
 *	MaoJian Wu
 *
 * Source:
 *	
 *
 * This file is a part of zfspear library.
 *
 *
 */

#include "stanzas.h"
#include "stream_element.h"
#include "xmpp_uri.h"
#include "jid.h"

Stanzas::Stanzas(const QString& tagName,const QString& ns):XmppElement(tagName,ns) {

}
int Stanzas::s_id_ = 0;
const Jid* Stanzas::From() const {
    Jid *jid=new Jid();
    QString from=Attribute("from");
    if (jid->FromString(from))
        return jid;
    else
        return NULL;
}
void Stanzas::SetFrom (const Jid& jid) {
    this->SetAttribute("from",jid.ToString());
}

const Jid* Stanzas::To() const {
    Jid *jid=new Jid();
    QString to=Attribute("to");
    if (jid->FromString(to))
        return jid;
    else
        return NULL;
}
void Stanzas::SetTo(const Jid& jid) {
    SetAttribute("to",jid.ToString());
}

QString Stanzas::Id() const {
    return Attribute("id");
}
void Stanzas::SetId(const QString& id) {
    SetAttribute("id",id);
}

QString Stanzas::Xmllang() const {
    return Attribute("xml:lang");

}
void Stanzas::SetXmllang(const QString& xmllang) {

    SetAttribute("xml:lang",xmllang);

}

QString Stanzas::type() const {
    return Attribute("type");
}
void Stanzas::SetType(const QString& type) {
    SetAttribute("type",type);
}
void Stanzas::GenerateId() {
    ++s_id_;
    QString id = "zfpear" + QString::number(s_id_);
    SetId(id);
}
